package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.BannerManagerService;
import com.mtnz.njk.entity.BannerEntity;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 首页管理控制层
 * @Author: FBL
 * @CreateDate: 2019\8\26 0026 8:19
 * @Version: 1.0
 */
@RestController
@RequestMapping("/banner")
@CrossOrigin
public class BannerManagerController {

    @Autowired
    BannerManagerService bannerManagerService;

    /**
     * 首页管理列表展示
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listBanner")
    public ResponseResult listBanner(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return bannerManagerService.listBanner(pageNum, pageSize);
    }

    /**
     * 首页管理列表编辑
     *
     * @param bannerEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateBanner")
    public ResponseResult updateBanner(@RequestBody BannerEntity bannerEntity) throws Exception {
        if(bannerEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return bannerManagerService.updateBanner(bannerEntity);
    }

    /**
     * 首页管理列表新增
     *
     * @param bannerEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertBanner")
    public ResponseResult insertBanner(@RequestBody BannerEntity bannerEntity) throws Exception {
        if(bannerEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return bannerManagerService.insertBanner(bannerEntity);
    }

    /**
     * 首页管理列表删除
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delBanner")
    public ResponseResult delBanner(String id) throws Exception {
        if(id == null || ("").equals(id))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return bannerManagerService.delBanner(id);
    }
}
